package com.digitalchina.lxnsy.viewholder;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.activity.old.WebViewActivity;
import com.digitalchina.lxnsy.entity.ProductStandardVO;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.MathExtend;
import com.digitalchina.lxnsy.widget.VerticalTextview;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/8/21 11:10
 * 修改备注：
 * ================================================
 */

public class SelectProductionHolderV2 extends BaseViewHolder<ProductStandardVO> {


    private TextView tvName;
    private TextView tvBuy;
    private VerticalTextview tvTips;
    private TextView tvTipsNull;
    private Map<String, String> map = new HashMap<>();


    public SelectProductionHolderV2(ViewGroup parent) {
        super(parent, R.layout.item_select_production_v2);
        tvName = $(R.id.tv_name);
        tvBuy = $(R.id.tv_buy);
        tvTips = $(R.id.tv_tips);
        tvTipsNull = $(R.id.tv_tips_null);
    }

    @Override
    public void setData(final ProductStandardVO data) {
        super.setData(data);

        tvName.setText(data.getName() + "");

        //  购买标准状态 0有效 1无效
        if (data.getValidityStatus() == 0) {
            tvBuy.setText("已购买");
            tvBuy.setBackgroundResource(R.drawable.ic_production_no_fee);
        } else {

            if (1 == data.getFeeType()) { // 收费
                tvBuy.setText("￥" + MathExtend.round(data.getFee(),2));
                tvBuy.setBackgroundResource(R.drawable.ic_production_fee);
            } else {
                tvBuy.setText("免费");
                tvBuy.setBackgroundResource(R.drawable.ic_production_no_fee);
            }
        }


        if (data.getStandardMsgList() != null && data.getStandardMsgList().size() > 0) {
            ArrayList<String> titleList = new ArrayList<>();
            tvTips.removeAllViews();
            tvTips.removeAllViewsInLayout();
            tvTips.setVisibility(View.VISIBLE);
            tvTipsNull.setVisibility(View.GONE);
            for (int i = 0; i < data.getStandardMsgList().size(); i++) {
                titleList.add(data.getStandardMsgList().get(i).getTitle());
            }

            tvTips.setTextList(titleList);
            tvTips.setText(12, 0, getContext().getResources().getColor(R.color.colorFontGray));//设置属性
            tvTips.setTextStillTime(3000);//设置停留时长间隔
            tvTips.setAnimTime(300);//设置进入和退出的时间间隔
            tvTips.setOnItemClickListener(new VerticalTextview.OnItemClickListener() {
                @Override
                public void onItemClick(int position) {
                    map.put("title", data.getStandardMsgList().get(position).getTitle());
                    map.put("url", data.getStandardMsgList().get(position).getUrl());
                    GotoUtil.gotoActivity((Activity) getContext(), WebViewActivity.class, "map", map);
                }
            });

            tvTips.startAutoScroll();
        } else {
            tvTips.setVisibility(View.GONE);
            tvTipsNull.setVisibility(View.VISIBLE);
        }

    }

}
